<%@ taglib prefix="app" uri="/app-tags"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>

<tiles:insertTemplate template="/tiles/layout.jsp">
	<tiles:putAttribute name="selected" value="usuarios" />
	<tiles:putAttribute name="submenu">
        <ul>
            <li><a href="${pageContext.request.contextPath}/users/list-users.action" class="users">Lista de usuarios</a></li>
			<li><a href="${pageContext.request.contextPath}/users/add-user.action" class="useradd">Nuevo usuario</a></li>
		</ul>
	</tiles:putAttribute>
	
	<tiles:putAttribute name="body">
		
		<div id="box"> 
        <h3>Permisos del usuario <b>${user.username}</b></h3> 
			<app:tablefilter tableId="permissions"/>		
			<table id="permissions" width="100%">
				<thead>
					<tr>
						<th>ID</th>
						<th width="400px">Edificio</th>
						<th>Resp de edificio</th>
						<th>Resp de gastos</th>
						<th>Resp de cobros</th>
					</tr> 
				</thead>
				<tbody>
				<c:forEach var="permission" items="${permissions}">
				<tr>
					<td><c:out value="${permission.id}" /><br/></td>
					<td><c:out value="${permission.nombre}" /><br/></td>
					
					<!-- administracion -->
					<c:if test="${permission.admin}">
					<td>SI
					<a href="${pageContext.request.contextPath}/users/del-permission.action?user.id=${user.id}&edificio.id=${permission.id}&type=ADMIN">
						<img src="${pageContext.request.contextPath}/img/icons/key_delete.png" title="Borrar Permiso" width="16" height="16" />
					</a>
					</td>
					</c:if>
					
					<c:if test="${!permission.admin}">
					<td>NO
					<a href="${pageContext.request.contextPath}/users/add-permission.action?user.id=${user.id}&edificio.id=${permission.id}&type=ADMIN">
						<img src="${pageContext.request.contextPath}/img/icons/key_add.png" title="Agregar Permiso" width="16" height="16" />
					</a>
					</td>
					</c:if>						
					
					<!-- gastos -->
					<c:if test="${permission.gasto}">
					<td>SI
					<a href="${pageContext.request.contextPath}/users/del-permission.action?user.id=${user.id}&edificio.id=${permission.id}&type=GASTO">
						<img src="${pageContext.request.contextPath}/img/icons/key_delete.png" title="Borrar Permiso" width="16" height="16" />
					</a>
					</td>
					</c:if>
					
					<c:if test="${!permission.gasto}">
					<td>NO
					<a href="${pageContext.request.contextPath}/users/add-permission.action?user.id=${user.id}&edificio.id=${permission.id}&type=GASTO">
						<img src="${pageContext.request.contextPath}/img/icons/key_add.png" title="Agregar Permiso" width="16" height="16" />
					</a>
					</td>
					</c:if>
					
					<!-- cobros -->
					<c:if test="${permission.cobro}">
					<td>SI
					<a href="${pageContext.request.contextPath}/users/del-permission.action?user.id=${user.id}&edificio.id=${permission.id}&type=COBRO">
						<img src="${pageContext.request.contextPath}/img/icons/key_delete.png" title="Borrar Permiso" width="16" height="16" />
					</a>
					</td>
					</c:if>
					
					<c:if test="${!permission.cobro}">
					<td>NO
					<a href="${pageContext.request.contextPath}/users/add-permission.action?user.id=${user.id}&edificio.id=${permission.id}&type=COBRO">
						<img src="${pageContext.request.contextPath}/img/icons/key_add.png" title="Agregar Permiso" width="16" height="16" />
					</a>
					</td>
					</c:if>					
				</tr>
				</c:forEach>
				</tbody>
			</table>
			
			<s:form action="add-permission" id="form" namespace="/users" validate="true" enctype="ISO-8859-1">
			<fieldset>
				<legend>NUEVO PERMISO</legend>
				<s:hidden name="user.id"></s:hidden>
				<s:select name="edificio.id" label="Edificio" required="true" list="edificios" listKey="id" listValue="nombre"/>
				
				<br>
				<input type="checkbox" name="type" value="ADMIN" id="type-1"/>
				Responsable de Edificio<br>
				
				<input type="checkbox" name="type" value="GASTO" id="type-2"/>
				Respnsable de gastos<br/>
				
				<input type="checkbox" name="type" value="COBRO" id="type-3"/>
				Reponsable de cobros<br/>
					
				<input type="hidden" id="__multiselect_form_type" name="__multiselect_type" value="" />

				
			</fieldset>
			
			
			<div align="center">
            	<input id="button1" type="submit" value="Guardar" /> 
			</div>
		</s:form>
			
		
		
        </div>
	</tiles:putAttribute>
</tiles:insertTemplate>